package top.hkyzf.study.leetcode.string;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-2-1 21:35
 */
public class 最长的美好子字符串_1763 {
    public String longestNiceSubstring(String s) {
        if (s.length() < 2) {
            return "";
        }
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            // 小写并且不包含大写，大写并且不包含小写
            if ((ch >= 'a' && !s.contains(String.valueOf((char)(ch - 32)))) || (ch <= 'Z' && !s.contains(String.valueOf((char)(ch + 32))))) {
                String s1 = longestNiceSubstring(s.substring(0, i));
                String s2 = longestNiceSubstring(s.substring(i+1));
                if (s1.length() < s2.length()) {
                    return s2;
                }
                return s1;
            }
        }
        return s;
    }

    @Test
    public void testLongestNiceSubString () {
        String s = "YazaAay";
        System.out.println(longestNiceSubstring(s));
    }
}
